package com.hsytech.dijiebao.base;


import android.app.ActivityManager;
import android.app.Application;
import android.app.ProgressDialog;
import android.content.Context;

import com.hsytech.dijiebao.MainActivity;
import com.hsytech.dijiebao.person.dao.InformationDao;
import com.hsytech.dijiebao.utils.HttpUtil;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import io.rong.imkit.RongIM;

/**
 * Created by Mo on 2015/7/6.
 */
public class BaseApplication extends Application {
	public static Context mApplicationContext;
	private static ProgressDialog dialog;
	public static InformationDao informationDao;

	@Override
	public void onCreate() {
		super.onCreate();
		HttpUtil.init(this);
		RongIM.init(getApplicationContext());

		initSystem();
		initurl();
		initDataBase();
		// initExterl();
	}

	private void initExterl() {

	}

	private void initDataBase() {
		informationDao = InformationDao.getInstance(getApplicationContext());

	}

	private void initSystem() {
		mApplicationContext = getApplicationContext();
		// CrashHandler.getInstance().init(getApplicationContext());
		SystemManager.getInstance();
		SystemSettings.ExitActivity.exitName = MainActivity.class.getSimpleName();
	}

	private void initurl() {
		ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this).build();
		ImageLoader.getInstance().init(config);
	}

	public static class MyDialog {

		public static void show(Context context) {
			if (dialog == null) {
				dialog = new ProgressDialog(context);
			}

			dialog.setTitle(null);
			dialog.setMessage("数据加载中请稍候...");
			dialog.setCanceledOnTouchOutside(false);
			dialog.setCancelable(false);
			dialog.show();
		}

		public static void dismiss() {
			if (dialog != null && dialog.isShowing()) {
				dialog.dismiss();
				dialog = null;
			}

		}

		public static boolean isShowing() {
			if (dialog != null && dialog.isShowing()) {
				dialog.isShowing();
				return true;
			}
			return false;
		}
	}

	/**
	 * ��õ�ǰ���̵�����
	 *
	 * @param context
	 * @return ���̺�
	 */
	public static String getCurProcessName(Context context) {

		int pid = android.os.Process.myPid();

		ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);

		for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {

			if (appProcess.pid == pid) {
				return appProcess.processName;
			}
		}
		return null;
	}
}
